package com.yufa.springcloud.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.yufa.springcloud.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
public class UserConstroller {

    @Autowired
    private EurekaClient eurekaClient;

    private int count = 0;

    @GetMapping(value = "/user/{id}")
    private User getUser(@PathVariable Long id) {

        System.out.println("begin" + id + (count++));
        if (id == 1) {
            throw new NullPointerException("2");
        }
        System.out.println(id);
        System.out.println(id);
        return new User().setDate(new Date()).setId(id);

    }

    @PostMapping(value = "/get-user")
    private User getUser(@RequestBody User user) {
        System.out.println(user);
        System.out.println(user);
        return user;
    }

    @GetMapping(value = "/eurekainfo")
    private String info() {
        InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("PROVIDER-USER", false);
        return instanceInfo.getHomePageUrl();
    }

}
